from flask_restful import Resource
from app import api,auth,celery,mail
from flask import jsonify,g,request
from app.models import *
from utils import *
from tasks import *

class wxAPI(Resource):
    decorators = [auth.login_required]
    def post(self):
        user = request.json.get('user') 
        content = request.json.get('content') 
        if not user:
            return jsonify({'code':10003,'msg':'please input wx user'})
        if not content:
            return jsonify({'code':10004,'msg':'please input wx content'})
        wx_data = {
            'user': user, 
            'content': content
          }
        task=send_async_wx.delay(wx_data)
        return jsonify({'code':200,'task_id':task.id,'msg':'添加队列成功'}) 


api.add_resource(wxAPI, '/devops/api/v1.0/wx', endpoint = 'wx')
